package accountManagementNew.utils;


import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.Map;

/**
 * @Author：lihonbin
 * @Version：1.0.0
 * @Date:2025/10/31
 * @Description: 时间工具类
 */
public class DateUtils {

    private DateUtils() {
    }

    private static final String YEAR_FORMAT = "yyyy";
    private static final String MONTH_FORMAT = "yyyy-MM";
    private static final String DATE_FORMAT = "yyyy-MM-dd";
    private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static final String FIRST_DAY = "firstDay";
    public static final String LAST_DAY = "lastDay";


    /**
     * 获取当前时间上个月份的第一天和最后一天
     *
     * @param dateTime 当前时间
     * @return
     */
    public static Map<String, LocalDateTime> getLastMonthFirstAndLastDay(LocalDateTime dateTime) {
        // 获取当前的年月
        YearMonth currentYearMonth = YearMonth.from(dateTime);
        // 获取上个月的年月
        YearMonth lastYearMonth = currentYearMonth.minusMonths(1);
        // 获取上个 月的第一天
        LocalDateTime firstDay = lastYearMonth.atDay(1).atStartOfDay();
        // 获取上个 月的最后一天
        LocalDateTime lastDay = lastYearMonth.atEndOfMonth().atTime(23, 59, 59);
        return Map.of(FIRST_DAY, firstDay, LAST_DAY, lastDay);
    }

}
